package cn.how2go.data.component;

import cn.how2go.common.vo.JT0200;
import cn.how2go.data.config.GPSTransToAMap;
import cn.how2go.data.entity.Cars;
import cn.how2go.data.entity.Cone;
import cn.how2go.data.entity.Location;
import cn.how2go.data.service.*;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2019/7/15.
 */
@Component
@RabbitListener(queues = RabbitmqQueue.LOCATION_QUEUE)
public class RabbitmqReceive {

    @Autowired
    private LocationService locationService;

    @Autowired
    private LocationHisService locationHisService;

    @Autowired
    private WarnningService warnningService;

    @Autowired
    private StatusService statusService;

    @Autowired
    private CarsService carsService;

    @Value("${api.url}")
    private String apiurl;

    @RabbitHandler
    public void process(JT0200 bean) {
        System.out.println("receive\r\n"+bean.toString());
        Cone param = new Cone();
        String simno = bean.getSimno();
        int lingNo = 12-simno.length();
        String ling = "";
        for(int i=0;i<lingNo;i++){
            ling += "0";
        }
        simno = ling+simno;
        param.setTermID(simno);
        param.setLon(bean.getLocation().getLongitude());
        param.setLat(bean.getLocation().getLatitude());
        double[] lnglat = GPSTransToAMap.transform(bean.getLocation().getLatitude(),bean.getLocation().getLongitude());
        param.setLon2(lnglat[1]);
        param.setLat2(lnglat[0]);
        String result2 = HttpRequest.post(apiurl)
                .body(JSONUtil.toJsonStr(param))
                .execute().body();
        System.out.println(result2);
    }
}
